package com.ccc.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ccc.dao.AdDao;
import com.ccc.model.Ad;
import com.ccc.model.User;

@Component("adService")
public class AdService {
	
	@Resource
	private AdDao adDao;
	
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean addAds(List<Ad> ads, User user, Integer currentTime){
		if(adDao.findAds(user, currentTime).size()>0){
			return false;
		}else{
			for(Ad a : ads){
				a.setCurrentTime(currentTime);
			    a.setUser(user);
				adDao.addAd(a);
			}
			return true;
		}
	}
	
	
	
}
